package com.linkhub.oms.admin.modules.logistic.freighttemplate.domain.dto;

import com.linkhub.oms.common.util.QtBigDecimalUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * <p>
 * 物流运费计算DTO
 * </p>
 *
 * @author Frank
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "物流运费计算DTO", description = "物流运费计算DTO")
@NoArgsConstructor
public class LogisticFreightCalculateDTO implements Serializable {
    /**
     * 必传
     */
    @ApiModelProperty(value = "渠道编码")
    @NotBlank
    private String channelCode;

    /**
     * 必传
     */
    @ApiModelProperty(value = "国家编码")
    @NotBlank
    private String countryCode;

    /**
     * 条件必传，国家有分区时必传
     */
    @ApiModelProperty(value = "邮编")
    private String postCode;

    /**
     * 订单中所有产品的体积和    体积/计泡系数=体积重    单位： kg
     */
    @ApiModelProperty(value = "总体积 单位：cm3")
    private BigDecimal volumeWeight;

    /**
     * 订单中所有产品的包裹重量和
     */
    @ApiModelProperty(value = "包裹重 单位：g")
    private BigDecimal packageWeight;

    @ApiModelProperty(value = "动态重量 单位：g")
    private BigDecimal dynamicWeight;

    /**
     * 执行计算的时间(用于筛选运费模板),默认服务器当前时间
     */
    @ApiModelProperty(value = "计算日期")
    private LocalDateTime calDate;

    public BigDecimal getVolumeWeight() {
        return QtBigDecimalUtil.defaultIfNull(volumeWeight, BigDecimal.ZERO);
    }

    public BigDecimal getPackageWeight() {
        return QtBigDecimalUtil.defaultIfNull(packageWeight, BigDecimal.ZERO);
    }

    public BigDecimal getDynamicWeight() {
        return QtBigDecimalUtil.defaultIfNull(dynamicWeight, BigDecimal.ZERO);
    }

    public LocalDateTime getCalDate() {
        if (Objects.isNull(calDate)) {
            return LocalDateTime.now();
        }
        return calDate;
    }
}
